
from fastapi import FastAPI
from contextlib import asynccontextmanager

from loguru import logger

from app.core.config import get_settings
from app.core.database import RedisPool, register_tortoise_orm
from app.events.register_logger import register_logger


@asynccontextmanager
async def lifespan(app: FastAPI):
    """
    应用生命周期管理 新版有buger
    :param app:
    """
    setting = get_settings()
    # 注册日志
    register_logger(setting)

    logger.info("应用启动中...")
    yield
    logger.info("应用关闭中...")
    # 清理资源，如关闭数据库连接
    await RedisPool.close()